package shop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Interceptor {
	private Console console;
	
	@Autowired
	public Interceptor(Console c) {
		super();
		this.console = c;
	}

	// tim: You should target public * shop.*Screen.*(..)
	// because output is what UI does (Service code throw exception or return result from service method
	@Around("execution(public * shop.*Screen.*(..))")
	public Object throwSystemError(ProceedingJoinPoint pjp) throws Throwable {
		try{
			return pjp.proceed();
		}catch(Exception e){
			console.println(e.toString());
		}
		return false;
	}
}
